﻿using ApiLib.AppStart;
using ApiLib.Cloud.Common;
using ApiLib.Cloud.Models;
using Furion.Schedule;
using Microsoft.AspNetCore.Builder;

namespace ApiLib.Cloud;

/// <summary>
/// 云服务配置
/// </summary>
public static class WebCloud
{
    /// <summary>
    /// 作为网关
    /// </summary>
    public static void Zuul(string key = "", bool useDb = true)
    {
        // MyCloudConstants.CloudType = CloudModalType.Zuul;
        MyCloudConstants.Config = new ServiceConfig
        {
            Key = key
        };
        GlobalConfig.Configures.Add((app, _) => { app.UseMiddleware<MyCloudMiddleware>(); });
        GlobalConfig.ScheduleOptionsBuilders.Add(builder => builder.AddJob<CloudHealthJob>(Triggers.PeriodSeconds(5)));
    }

    /// <summary>
    /// 作为服务
    /// </summary>
    /// <param name="config">服务信息</param>
    public static void Register(ServiceConfig config)
    {
        // MyCloudConstants.CloudType = CloudModalType.Service;
        MyCloudConstants.Config = config;
        GlobalConfig.ScheduleOptionsBuilders.Add(builder =>
            builder.AddJob<CloudRegisterJob>(Triggers.PeriodMinutes(3).SetRunOnStart(true)));
    }
}